package com.fenqing.leetcode.code.t400_500;

import com.fenqing.annotations.Execute;
import com.fenqing.core.Topic;

import java.util.HashMap;
import java.util.Map;

/**
 * @author fenqing
 */
public class Topic454 extends Topic {
    /**
     * 构造器
     *
     * @param input1 输入1
     * @param input2 輸入2
     * @param input3 輸入3
     * @param input4 輸入4
     */
    public Topic454(String input1, String input2, String input3, String input4) {
        super(input1, input2, input3, input4);
    }

    @Execute
    public int fourSumCount(int[] nums1, int[] nums2, int[] nums3, int[] nums4) {
        Map<Integer, Integer> hash = new HashMap<>();
        for (int num1 : nums1) {
            for (int num2 : nums2) {
                int num = num2 + num1;
                int val = hash.getOrDefault(num, 0);
                hash.put(num, val + 1);
            }
        }
        int count = 0;
        for (int num3 : nums3) {
            for (int num4 : nums4) {
                int num = num3 + num4;
                Integer val = hash.get(-num);
                if (val != null) {
                    count += val;
                }
            }
        }
        return count;
    }

    public static void main(String[] args) {
        Topic454 topic454 = new Topic454(
                """
                [1,2]
                """,
                """
                [-2,-1]
                """,
                """
                [-1,2]
                """,
                """
                [0,2]
                """);
        int run = topic454.run();
        System.out.println(run);
    }
}
